<?php 
/**************************************************/
## Class Name - Model_PLAN (Contains all the functions related cms pages of the project)
## Created By - Techmodi (19/08/2011)
/**************************************************/

class Model_PLAN extends Database
{	
	function Model_PLAN() {	
		$this->plan = MEM_PLAN;		
		$this->Database();
	}
	
	// Add Plan
	function addPlan($array) {
		$this->InsertData($this->plan, $array);
	}
	
	
	## List all plan
	function getAllPlan($search='',$col1='',$col2='',$limit='',$offset='') {
		$fields = array();	
		$tables = array($this->plan);
		if($col1 =='0')
		{
			$order = array("name ASC");
		}
		else if($col2 =='0')
		{
			$order = array("price ASC");
		}		
		else if($col1 =='1')
		{
			$order = array("name DESC");
		}
		else if($col2 =='1')
		{
			$order = array("price DESC");
		}
		else 
		{
			$order = array("plan_id ASC");
		}
		
		$result1 = $this->SelectData($fields,$tables, $where= array("name LIKE '%".$search."%'"), $order , $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get Plan details by id
	function getPlanDetailsById($plan_id) {
		$fields = array();	
		$tables = array($this->plan);
		$result1 = $this->SelectData($fields,$tables, $where= array("plan_id='".$plan_id."'"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
		
	## Edit menu by id
	function editPlanById($array, $Id){
		$this->UpdateData($this->plan,$array,"plan_id",$Id,0);
	}
	
	## Update cms page status with multiple ids
	function updateMultipleCmsStatus($ids, $status) {
		$sql = "UPDATE ".$this->plan." SET status='".$status."' WHERE plan_id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	
	// Global check plan name exist or not	
	function Checkplanname($name) {
		$fields=array('');
		$tables=array($this->plan);
		$where=array("name='".$name."'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0);
		$result= $this->FetchRow($result1);
		return $result;		
	}
	
	## List all plan insted of free
	function getAllPlanInstedOfFree() {
		$fields = array();	
		$tables = array($this->plan);
		$result1 = $this->SelectData($fields,$tables, $where= array("plan_id !=1"), $order , $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
}
?>